export default {
	data() {
		return {
			
		}
	},
	computed: {

	},
	methods: {
	// 删除图片
	deletePic(event) {
		this[`fileList${event.name}`].splice(event.index, 1)
	},
	// 新增图片
	async afterRead(event) {
		//console.log(event)
		// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
		let lists = [].concat(event.file)
		let fileListLen = this[`fileList${event.name}`].length
		lists.map((item) => {
			this[`fileList${event.name}`].push({
				...item,
				status: 'uploading',
				message: '上传中'
			})
		})
		
		for (let i = 0; i < lists.length; i++) {
			 let result = await this.uploadFilePromise(lists[i].url)
			 let res = JSON.parse(result);
			let item = this[`fileList${event.name}`][fileListLen]
			this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
				status: 'success',
				message: '',
				name : res.name,
				url: res.url
			}))
			fileListLen++
		}
		
	},
	uploadFilePromise(url) {
		return new Promise((resolve, reject) => {
			let uploadTask = uni.uploadFile({
				url: this.site_url+'mall/api/ma/file/uploadFile', // 仅为示例，非真实的接口地址
				filePath: url,
				header:{
					'app-id' : 'wxa8e3e85a46c85947',
					'third-session': uni.getStorageSync('third-session') ? uni.getStorageSync('third-session') : ''
				},
				name: 'file',
				// formData: {
				// 	user: 'test'
				// },
				// complete: (res) => {
				// 	console.log(res)
				// },
				success: (res) => {
					setTimeout(() => {
						resolve(res.data)
					}, 1000)
				}
			});
	
			// uploadTask.onProgressUpdate((res) => {
			// 	console.log('上传进度' + res.progress);
			// 	console.log('已经上传的数据长度' + res.totalBytesSent);
			// 	console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
			// 	// 测试条件，取消上传任务。
			// 	if (res.progress > 50) {
			// 		uploadTask.abort();
			// 	}
			// });
	
		})
	
	},


	}

}
